// 接口二次封装包装
import common from "@/utils/main";
import tokenUtils from "@/utils/token-utils";
import router from "@/router";
import api from "@/utils/api";
import elUtils from "@/utils/el-utils";
import {ElMessage} from "element-plus";

export default {
    // 退出登录
    loginOut() {
        tokenUtils.removeToken()
        common.setKeyVal("system", "isLogin", false, true);
        common.setKeyVal('system', 'userInfo', {}, true)
        router.push({name: "Login"});
        ElMessage({
            type: "success",
            message: "login out success!",
        });
    },


    //获取用户信息
    getUser(name = '', is_resd = false) {
        if (String(is_resd) == 'true') {
            elUtils.startElLoading()
            api.userInfo().then((res) => {
                elUtils.endElLoading()
                common.setKeyVal("system", "userInfo", res.data.userinfo, true);
            })
        }
        let userInfo = common.getKeyVal("system", "userInfo", true);
        console.log(userInfo)

        return name ? userInfo[name] : userInfo
    }
};
